package com.interesting.client.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.interesting.R;
import com.interesting.base.utils.Constant;
import com.interesting.client.application.AppHolder;
import com.interesting.client.bean.Message;

/** 用户发表的joke */
public class UserMesgListAdapter extends BaseAdapter {

	private Context context;
	private List<Message> listData;
	private LayoutInflater inflater;

	private class ViewHolder {
		public TextView content, state, time;
		public ImageView photo;
	}

	public UserMesgListAdapter(Context context, List<Message> listData) {
		this.context = context;
		this.listData = listData;
		inflater = LayoutInflater.from(context);
	}

	@Override
	public int getCount() {
		return listData.size();
	}

	@Override
	public Object getItem(int position) {
		return listData.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		final Message msg = listData.get(position);
		if (convertView == null) {
			convertView = inflater.inflate(R.layout.usermesg_list_item_adapter, null);
			ViewHolder vh = new ViewHolder();
			vh.content = (TextView) convertView.findViewById(R.id.usermesg_list_item_content);
			vh.state = (TextView) convertView.findViewById(R.id.usermesg_list_item_state);
			vh.time = (TextView) convertView.findViewById(R.id.usermesg_list_item_time);
			vh.photo = (ImageView) convertView.findViewById(R.id.usermesg_list_item_photo);
			convertView.setTag(vh);
		}
		ViewHolder holder = (ViewHolder) convertView.getTag();
		holder.content.setText(msg.getContent());
		if (msg.getMinImgPath() != null && !msg.getMinImgPath().equals("")) {
			AppHolder.getInsatnce().imageLoader.DisplayImage(Constant.IMGPATH + "/" + msg.getMinImgPath(),
					holder.photo, R.drawable.ic_user_default);
		}
		holder.state.setText(msg.getNstate());
		holder.time.setText(msg.getNptime());
		return convertView;
	}

}
